package com.course.app.transformer;

import com.course.app.api.data.TaskEventDTO;
import com.course.domain.model.TaskEvent;

import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * Created by Justin on 2017/5/30.
 */
public class TaskEventTransformer {

    public static Map<Integer, TaskEventDTO> toEventMap(List<TaskEvent> taskEventList) {
        return taskEventList.stream()
                .map(TaskEventTransformer::toEvent)
                .collect(Collectors.toMap(TaskEventDTO::getId, Function.identity()));
    }

    private static TaskEventDTO toEvent(TaskEvent taskEvent) {
        TaskEventDTO eventDTO = new TaskEventDTO();
        eventDTO.setId(taskEvent.getId());
        eventDTO.setTitle(taskEvent.getTitle());
        eventDTO.setDetail(taskEvent.getDetail());
        eventDTO.setMinutes(taskEvent.getMinutes());
        return eventDTO;
    }
}
